package com.jiahuiwen.mediator;

public class MotherBoard implements Mediator {

	private CDDriver cdDriver = null;
	private CPU cpu = null;
	private VideoCard videoCard = null;
	private SoundCard soundCard = null;
	
	
	
	public void setCdDriver(CDDriver cdDriver) {
		this.cdDriver = cdDriver;
	}



	public void setCpu(CPU cpu) {
		this.cpu = cpu;
	}



	public void setVideoCard(VideoCard videoCard) {
		this.videoCard = videoCard;
	}



	public void setSoundCard(SoundCard soundCard) {
		this.soundCard = soundCard;
	}



	@Override
	public void changed(Colleague colleague) {
		// TODO Auto-generated method stub
		if (colleague == cdDriver) {
			this.operateCDDriverReadData((CDDriver)colleague);
		} else if (colleague == cpu) {
			this.operateCPU((CPU)colleague);
		}
	}



	private void operateCPU(CPU colleague) {
		// TODO Auto-generated method stub
		String videoData = colleague.getVideoData();
		String soundData = colleague.getSoundData();
		
		this.videoCard.showData(videoData);
		this.soundCard.soundData(soundData);
	}



	private void operateCDDriverReadData(CDDriver colleague) {
		// TODO Auto-generated method stub
		String data = colleague.getData();
		this.cpu.executeData(data);
	}

}
